﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Pipes;

namespace LulzSea
{
    public partial class Console : Form
    {
        //static string vbNewLine = "\r\n";
        public string[] args2;
        public Console()
        {
            InitializeComponent();
        }

        public void cWrite(string text_to_write)
        {
            if (InvokeRequired)
            {
                this.Invoke(new Action<string>(cWrite), new object[] { text_to_write });
                return;
            }

            textBox1.Text += "\r\n" + text_to_write;
        }

        private void bwCommands_DoWork(object sender, DoWorkEventArgs e)
        {
            cWrite("bwCommands BackgroundWorker object started...");
            cWrite("Starting named pipe...");
            while (true)
            {
            using (NamedPipeServerStream pipeStream = new NamedPipeServerStream("_djmati11s_pipe_dont_touch_LulzSea"))
            {
                cWrite("Named pipe created...");
                cWrite("Waiting for connection...");
                
                    pipeStream.WaitForConnection();
                    cWrite("Connected to client...");
                    using (StreamReader sr = new StreamReader(pipeStream))
                    {
                        string temp;

                        while ((temp = sr.ReadLine()) != null)
                        {
                            cWrite(DateTime.Now + ":" + temp);
                        }
                    }
                    cWrite("Connection has ended...");
                }
                
            }
        
        }
        

        private void Console_Load(object sender, EventArgs e)
        {
            bwCommands.RunWorkerAsync();
        }
    }
}
